package cn.yr.oss.configuration;

import cn.yr.oss.OssKit;
import cn.yr.oss.UpyOss;
import cn.yr.oss.properties.OssProperties;
import cn.yr.oss.properties.OssUpyProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 又拍云配置类
 * @author Lang 1102076808@qq.com
 * @date 2021-04-08 22:13
 */
@Configuration
@EnableConfigurationProperties({OssUpyProperties.class, OssProperties.class})
@ConditionalOnProperty(
		prefix = "oss",
		name = "sdk",
		havingValue = "upy"
)
public class OssUpyConfiguration {


	@Autowired
	private OssUpyProperties ossUpyProperties;
	@Autowired
	private OssProperties ossProperties;

	@Bean
	public UpyOss upyOss(){
		return new UpyOss(ossUpyProperties.getUsername(),ossUpyProperties.getPassword()
				,ossUpyProperties.getBucket(),ossProperties.getDomain());
	}

	@Bean
	public OssKit ossKit(){
		OssKit ossKit = new OssKit();
		ossKit.setOss(upyOss());
		return ossKit;
	}

}
